// IconImage.cpp: implementation of the IconImage class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "IconImage.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(IconImage, Image)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IconImage::IconImage(HINSTANCE hinst, LPTSTR name)
{
	m_hinst = hinst;
	m_hicon = NULL;
	m_name = (LPTSTR)::malloc((lstrlen(name) + 1) * sizeof(TCHAR));
	m_bName = TRUE;
	loadImage();
}

IconImage::IconImage(HINSTANCE hinst, int id)
{
	m_hinst = hinst;
	m_hicon = NULL;
	m_name = MAKEINTRESOURCE(id);
	m_bName = FALSE;
	loadImage();
}

IconImage::~IconImage()
{
	if (m_bName)
		::free(m_name);
}

BOOL IconImage::loadImage()
{
	m_hicon = ::LoadIcon(m_hinst, m_name);
	return (m_hicon != NULL);
}

void IconImage::paint(CDC* pDC, AWTCanvas* canvas)
{
	pDC->DrawIcon(0,0,m_hicon);
}

CSize IconImage::getSize()
{
	if (m_hicon == NULL)
		return CSize(0,0);
	CSize sz;
	sz.cx = ::GetSystemMetrics(SM_CXICON);
	sz.cy = ::GetSystemMetrics(SM_CYICON);
	return sz;
}

